package com.demo.test.rpc.config;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.context.annotation.Configuration;

import com.bluering.framework.common.log.Logger;

@Aspect
@Configuration
public class DemoTestConfig {

	@Around("execution(* com.demo.test.service.impl..*.*(..)) or execution(* com.demo.test.rpc.api.impl..*.*(..))")
    public Object info(ProceedingJoinPoint jp){
		long startTime = System.currentTimeMillis();
		Logger logger = Logger.getLogger(jp.getTarget().getClass());
		logger.info("调用方法开始:【" + jp.getTarget().getClass() + "."+ jp.getSignature().getName() + "()】");
		StringBuffer args = new StringBuffer();
		for (Object arg : jp.getArgs()) {
			args.append("【");
			args.append(arg);
			args.append("】");
		}
		logger.info("入参:" + args.toString());
		try {
			Object result = jp.proceed();
			return result;
		} catch (Throwable e) {
			logger.error("【"+jp.getTarget().getClass() + "."+ jp.getSignature().getName() + "()】调用出错:"+e.getMessage(),e);
			throw new RuntimeException(e.getMessage(),e.getCause());
		} finally {
			logger.info("调用方法结束:【" + jp.getTarget().getClass() + "."+ jp.getSignature().getName() + "() 】耗时:"+(System.currentTimeMillis()-startTime)+"ms");
		}
    }
	

}
